FROM node:18-alpine

# 设置工作目录
WORKDIR /app

# 设置npm国内镜像源
RUN npm config set registry https://registry.npmmirror.com && \
    npm config set proxy http://192.168.10.4:10809 && \
    npm config set https-proxy http://192.168.10.4:10809

# 复制package文件
COPY package*.json ./

# 安装依赖
RUN npm install

# 复制源代码
COPY . .

# 构建应用
RUN npm run build

# 使用node serve提供静态文件服务
FROM node:18-alpine

# 设置工作目录
WORKDIR /app

# 设置npm国内镜像源
RUN npm config set registry https://registry.npmmirror.com

# 复制构建结果
COPY --from=0 /app/dist .

# 安装serve
RUN npm install -g serve

# 暴露端口
EXPOSE 3000

# 启动静态文件服务
CMD ["serve", "-s", ".", "-l", "3000"]
